<?php

use yii\helpers\Html;
use yii\grid\GridView;


$this->title = Yii::t('app', 'Products');
$this->params['breadcrumbs'][] = $this->title;
?>

<style type="text/css">
    .cs1{margin:2px 5px;} 
</style>

<div class="product-index">

    <div class="box">
        <div class="box-header">
            <?= Html::a(Yii::t('app', 'Create Product'), ['create'], ['class' => 'btn btn-success']) ?>
        </div>
        <div class="box-body">
        <p>
             <?php echo $this->render('_search', ['model' => $searchModel,'customer'=>$customer]); ?>
        </p>

            <?= GridView::widget([
                'dataProvider' => $dataProvider,
                'layout'  =>  "{items}\n{summary}\n{pager}",
                'columns' => [
                    ['class' => 'yii\grid\SerialColumn'],
                    [
                        'headerOptions' => ['width' => '10%'],
                        'attribute' => Yii::t('app.customer', 'Name'),
                        'value' => function ($model) {
                                return $model->customer->name;
                            },
                    ],
                    [
                        'headerOptions' => ['width' => '10%'],
                        'attribute' => Yii::t('app.customer', 'Payment'),
                        'value' => function ($model) {
                                return $model->customer->payment;
                            },
                    ],
                    [
                        'attribute' => 'name',
                        'headerOptions' => ['width' => '10%'],
                        'value' => function ($model) {
                                return $model->name;
                        },
                    ],
                    [
                        'attribute' => 'code',
                        'headerOptions' => ['width' => '10%'],
                        'value' => function ($model) {
                                return $model->code;
                        },
                    ],
                    [
                        'attribute' => 'price',
                        'headerOptions' => ['width' => '10%'],
                        'value' => function ($model) {
                                return $model->price;
                        },
                    ],
                    [
                        'attribute' => Yii::t('app.product', 'Cost Price'),
                        'headerOptions' => ['width' => '10%'],
                        'value' => function ($model) {
                                return $model->costPrice;
                            },
                    ],
                    [
                      'attribute' => Yii::t('app.product', 'Amount Received'),
                      'headerOptions' => ['width' => '10%'],
                      'value' => function($model){
                            return $model->incomePrice;
                      }
                    ],


                    [
                          'attribute' => Yii::t('app.product', 'Oper ID'),
                          'headerOptions' => ['width' => '10%'],
                          'value' => function($model){
                                return $model->operName;
                          }
                    ],

                    [
                        'attribute' => 'status',
                        'headerOptions' => ['width' => '5%'],
                        'value' => function ($model) {
                                return isset(Yii::$app->params['product_status'][$model->status])?Yii::$app->params['product_status'][$model->status]:'';
                            },
                    ],

                    [
                      'attribute' => 'user_id',
                      'headerOptions' => ['width' => '5%'],
                      'value' => function($model){

                            return $model->userName;
                      }
                    ],

                    [
                        'label'=>'操作',
                        'format'=>'raw',
                        'headerOptions' => ['width' => '10%'],
                        'value' => function($model){

                            $url  = sprintf("/product/product/view?id=%d", $model->id); //查看
                            $url4  = sprintf("/cost/cost/cost?product_id=%d", $model->id); //成本项
                            $url3  = sprintf("/product/invoice/index?product_id=%d", $model->id); //INVOICE

                            $url2  = sprintf("/product/product/close?id=%d", $model->id); //关团

                            $str  = Html::a('查看',$url,['title' =>'查看','class'=>'btn btn-info btn-xs cs1',]);

                            
                            $str  .= Html::a('成本项',$url4,['title' =>'成本项','class'=>'btn btn-primary btn-xs cs1',]);

                            $str  .= Html::a('INVOICE',$url3,['title' =>'INVOICE','class'=>'btn btn-success btn-xs cs1',]);
                                
                            if($model->user_id == \yii::$app->user->id && $model->status != 20){
                                
                                if($model->status != 10){
                                    $str .= Html::a('关团', ['close', 'id' => $model->id], ['class' => 'btn btn-warning btn-xs cs1','data' => [
                                        'confirm' => Yii::t('app', '你确定要关团吗?'),
                                        'method' => 'post',
                                    ],]);
                                }

                                if($model->status != 10){
                                    $str .= Html::a('删除团组', ['del', 'id' => $model->id], ['class' => 'btn btn-danger btn-xs cs1','data' => [
                                        'confirm' => Yii::t('app', '你确定要删除团吗?'),
                                        'method' => 'post',
                                    ],]);
                                }
                            }
                           
                            return $str;
                         }
                    ],

                ],
            ]); ?>
        </div>
    </div>
</div>
